#include <bits/stdc++.h>
#include <climits>
using namespace std;

class Solution {
public:
    int divide(int dividend, int divisor) {
        //被除数最大时
        if(dividend == INT_MAX){
            if(divisor == 1) return INT_MAX;
            else if(divisor == -1) return -INT_MAX;
        }
        if(dividend == INT_MIN){
            if(divisor == 1) return INT_MIN;
            else if(divisor == -1) return INT_MAX;
        }
        //除数最大时
        if(divisor == INT_MAX){
            if(dividend == INT_MAX) return 1;
            else if(dividend == INT_MIN) return -1;
            return 0;
        }

        if(divisor == INT_MIN){
            if(dividend == INT_MIN) return 1;
            return 0;
        }



        int flag = (dividend>>31) ^ (divisor>>31);    //判断正负（异号）
        if(dividend > 0) dividend = -dividend;
        if(divisor > 0) divisor = -divisor;
        int ans = 0;
        int cnt = 1;
        while(dividend <= divisor){
            dividend -= divisor;

            ans += cnt;
            //避免溢出
            if(INT_MIN >> 1 < divisor){
                divisor <<= 1;
                cnt <<= 1;
            }
        }

        while(dividend < 0){
            divisor >>= 1;
            cnt >>= 1;
            if(cnt == 0) break; //剪枝
            if(dividend > divisor) continue;
            dividend -= divisor;
            ans += cnt;
        }
        
        ans = flag ? -ans : ans;
        return ans;
    }
};

int main(){
    Solution solution;
    solution.divide(1100540749, -1090366779);
}